package com.wagn.config.exceptionHandler;

import com.wagn.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class EHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error();
    }

    @ExceptionHandler(MyException.class)
    @ResponseBody
    public R error1(MyException e){
        log.error(e.getMsg());
        return R.error().code((int) e.getCode()).message(e.getMsg());
    }

}
